package awk.jdk8;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.WeekFields;

/**
 * created with IDEA
 *
 * @author haifeng.wang
 * @since 2019-07-22-15:43
 */
public class DateTimeUtils {

    public static LocalTime parseDateTime(LocalTime localTime,DateTimeFormatter formatter){
        String format = localTime.format(formatter);
        return LocalTime.parse(format);
    }

    public static LocalTime parseDateTime(DateTimeFormatter formatter){
        //时区
        LocalTime localTime = LocalTime.now(ZoneId.systemDefault());
        String format = localTime.format(formatter);
        return LocalTime.parse(format);
    }

    public static LocalTime getLocalTime(){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
        LocalTime localTime = LocalTime.now(ZoneId.systemDefault());
        String format = localTime.format(formatter);
        return LocalTime.parse(format);
    }

    /**
     * 获取若干天之前的某一天    toDay.plus(days, ChronoUnit.DAYS);
     * @param days 相差的天数
     */
    public static LocalDate LocalDatepreDay(int days){
        LocalDate toDay = LocalDate.now(ZoneId.systemDefault());
        return toDay.minus(days, ChronoUnit.DAYS);
    }



    public static void main(String[] args) {
        WeekFields of = WeekFields.of(DayOfWeek.MONDAY, 4);
    }
}
